package com.psmorandi.peschampweb.android.tab;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.psmorandi.peschampweb.android.EOpcoesMenu;
import com.psmorandi.peschampweb.android.tab.listeners.OnMenuLateralSelecionadoListener;

public class MenuFragment extends ListFragment {

	OnMenuLateralSelecionadoListener mCallback;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		int layout = android.R.layout.simple_list_item_activated_1;

		// Create an array adapter for the list view, using the Ipsum headlines
		// array
		setListAdapter(new ArrayAdapter<String>(getActivity(), layout,
				EOpcoesMenu.getNomesOpcoesMenu()));
	}

	@Override
	public void onStart() {
		super.onStart();
		getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);

		// This makes sure that the container activity has implemented
		// the callback interface. If not, it throws an exception.
		try {
			mCallback = (OnMenuLateralSelecionadoListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement OnMenuItemSelectedListener");
		}
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		// Notify the parent activity of selected item
		mCallback.onMenuLateralSelecionado(position);

		// Set the item as checked to be highlighted when in two-pane layout
		getListView().setItemChecked(position, true);
	}

}
